$(function() {
	var $searchField = $("#searchDiv input[type=text]");
	var $searchButton = $("#searchDiv button");
	var $progressbar = $("#progressbar");
	
	$searchField.focus();
	$progressbar.progressbar({value: false});
	
	$searchField.keypress(function( event ) {
		if ( event.which == 13 ) {
			event.preventDefault();
			$searchButton.button().click();
		}
	});
	
	$searchButton.button().click(function( event ) {
		$.ajax({
		    type: 'get',
		    url: 'search',
		    data: 'query=' + $searchField.val(),
		    beforeSend: function() {
		    	$searchField.prop("disabled", true);
		    	$searchButton.button("disable");
		    	$progressbar.show();
		    },
		    complete: function(){
		    	$searchField.prop("disabled", false);
		    	$searchButton.button("enable");
		    	$progressbar.hide();
		    },
		    success: function(data) {
		    	$("#contentDiv").html(data);
		    }
		});
	});
});